package com.zqwh.yj.sdk.model;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.zqwh.yj.sdk.R;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by eason.yang on 2019/6/4.
 */

public class SoundModelImpl implements SoundModel {
    private Context mContext;
    private SoundPool mSoundPool; //本机语音播放
    private Map<Integer, Integer> mSoundMap = new HashMap<>();

    public SoundModelImpl(Context context) {
        this.mContext = context;
        initSound();
    }

    private void initSound(){
        mSoundPool = new SoundPool(12, AudioManager.STREAM_MUSIC, 5);
        mSoundMap.put(SOUND_ENROLL_SUCCESS, mSoundPool.load(mContext, R.raw.enroll_success_00, 1)); //登记成功
        mSoundMap.put(SOUND_ENROLL_FAIL, mSoundPool.load(mContext, R.raw.enroll_fail_02, 1)); //登记失败
        mSoundMap.put(SOUND_VERIFY_SUCCESS, mSoundPool.load(mContext, R.raw.verify_success_33, 1)); //验证成功
        mSoundMap.put(SOUND_VERIFY_FAIL, mSoundPool.load(mContext, R.raw.verify_fail_32, 1)); //验证失败
        mSoundMap.put(SOUND_PUT_FINGER, mSoundPool.load(mContext, R.raw.put_finger_27, 1)); //请放手指
        mSoundMap.put(SOUND_PUT_AGAIN, mSoundPool.load(mContext, R.raw.put_again_23, 1)); //请再放一次
        mSoundMap.put(SOUND_PUT_RIGHT, mSoundPool.load(mContext, R.raw.put_right_26, 1)); //请正确放置手指
        mSoundMap.put(SOUND_B_1, mSoundPool.load(mContext, R.raw.b_35, 1)); //滴1
        mSoundMap.put(SOUND_B_2, mSoundPool.load(mContext, R.raw.b_36, 1)); //滴2
        mSoundMap.put(SOUND_BB_1, mSoundPool.load(mContext, R.raw.bb_37, 1)); //滴滴1
        mSoundMap.put(SOUND_BB_2, mSoundPool.load(mContext, R.raw.bb_38, 1)); //滴滴2
        mSoundMap.put(SOUND_WARNING, mSoundPool.load(mContext, R.raw.warning, 1));
    }

    @Override
    public void playVoice(int id){
        if (id <= mSoundMap.size()) {
            mSoundPool.play(mSoundMap.get(id), 1, 1, 1, 0, 1);
        }
    }
}
